package com.model.defaults.actionbar;

import java.util.Map;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;

import com.core.hibernate.ExceptionHandler;
import com.core.hibernate.exceptionevent.ExceptionEvent;
import com.model.UserContextName;
import com.model.defaults.actionbar.entities.ModelDefaultActionbarItemsGroup;
import com.model.defaults.actionbar.entities.ModelDefaultActionbarItemsProject;
import com.model.defaults.actionbar.entities.ModelDefaultActionbarItemsReport;
import com.model.defaults.actionbar.entities.ModelDefaultActionbarItemsRole;
import com.model.defaults.actionbar.entities.ModelDefaultActionbarItemsTask;
import com.model.defaults.actionbar.entities.ModelDefaultActionbarItemsTeamMember;
import com.model.defaults.actionbar.entities.ModelDefaultActionbarItemsUser;
import com.model.defaults.actionbar.entities.ModelDefaultActionbarItemsVersion;


public class ModelDefaultActionbarItems {

	public static void createActionBarItems ( Session session,
	                                          Map <String, UserContextName> userContexts ) {


		Transaction transaction = null;

		try {
			transaction = session.beginTransaction();



			ModelDefaultActionbarItemsProject.createActionBarItems(session, userContexts);

			ModelDefaultActionbarItemsTask.createActionBarItems(session, userContexts);

			ModelDefaultActionbarItemsUser.createActionBarItems(session, userContexts);

			ModelDefaultActionbarItemsVersion.createActionBarItems(session, userContexts);

			ModelDefaultActionbarItemsRole.createActionBarItems(session, userContexts);

			ModelDefaultActionbarItemsGroup.createActionBarItems(session, userContexts);

			ModelDefaultActionbarItemsReport.createActionBarItems(session, userContexts);

			ModelDefaultActionbarItemsTeamMember.createActionBarItems(session, userContexts);

			transaction.commit();

		} catch ( RuntimeException runtimeException ) {
			ExceptionHandler.handleException(runtimeException, new ExceptionEvent(ExceptionEvent.ACTIONBAR));
			if ( transaction != null ) {
				if ( transaction.isActive() ) {
					try {
						transaction.rollback();
					} catch ( HibernateException hibernateException ) {
						ExceptionHandler.handleException(hibernateException, new ExceptionEvent(ExceptionEvent.ACTIONBAR));
					}
				}
			}
		}
	}
}
